package com.supply.dl.activity.fragment;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.ScrollView;

import butterknife.BindView;
import butterknife.ButterKnife;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.supply.dl.R;
import com.supply.dl.activity.*;
import com.supply.dl.activity.seachmode.*;
import com.supply.dl.bean.BaseItemBean;
import com.supply.dl.bean.WorkFunctionBean;
import com.supply.dl.constant.Constants;
import com.supply.dl.utils.CommonNormalAdapterUtil;
import com.supply.dl.utils.RecyclerViewUtil;
import com.supply.dl.utils.Utils;
import com.supply.dl.view.MaxRecyclerView;
import com.supply.dl.widget.LoadTipFailedLayout;
import com.supply.dl.widget.adapter.CommonNormalAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * 工作主界面
 */
public class WorkFragment extends ViewPagerFragment implements View.OnClickListener {

    Activity mActivity;

    @BindView(R.id.fragment_work_main_recyclerView)
    MaxRecyclerView mRecyclerView;

    @BindView(R.id.fragment_work_main_scanImageView)
    ImageView imgScan;
    CommonNormalAdapter mGridViewAdapter;
    List<BaseItemBean> itemList;

    @BindView(R.id.fragment_work_layout_scrollView)
    ScrollView scrollView;

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        this.mActivity = activity;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_work_layout, container, false);
        ButterKnife.bind(this, view);
        initView();
        initData();
        initRecyclerView();
        return view;
    }

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        //在这里初始UI组件
        loadTipFailedLayout = (LoadTipFailedLayout) findViewById(R.id.layout_load_failed);
        loadTipFailedLayout.setRestartOnClickListener(this);
        loadTipFailedLayout.setLoadText(getString(R.string.since_help_loading));
        loadTipFailedLayout.setNormalText(R.string.since_help_loading_finish);
        loadTipFailedLayout.setState(LoadTipFailedLayout.STATE_FINISH);
        imgScan.setOnClickListener(this);
    }

    private void initView() {

    }

    private void initData() {
        scrollView.smoothScrollTo(0, 0);
        itemList = new ArrayList<>();
        WorkFunctionBean workFunctionBean1 = new WorkFunctionBean(getResourcesString(R.string.inbound_location), R.mipmap.pic_1);
        WorkFunctionBean workFunctionBean2 = new WorkFunctionBean(getResourcesString(R.string.order_inbound), R.mipmap.pic_2);
        WorkFunctionBean workFunctionBean3 = new WorkFunctionBean(getResourcesString(R.string.notice_to_inbound), R.mipmap.pic_3);
        WorkFunctionBean workFunctionBean4 = new WorkFunctionBean(getResourcesString(R.string.take_delivery_confirm), R.mipmap.pic_4);
        WorkFunctionBean workFunctionBean5 = new WorkFunctionBean(getResourcesString(R.string.outbound_location), R.mipmap.pic_5);
        WorkFunctionBean workFunctionBean6 = new WorkFunctionBean(getResourcesString(R.string.order_outbound), R.mipmap.pic_6);
        WorkFunctionBean workFunctionBean7 = new WorkFunctionBean(getResourcesString(R.string.notice_to_out_outbound), R.mipmap.pic_7);
        WorkFunctionBean workFunctionBean8 = new WorkFunctionBean(getResourcesString(R.string.deliver_goods_confirm), R.mipmap.pic_8);

        WorkFunctionBean workFunctionBean9 = new WorkFunctionBean(getResourcesString(R.string.new_built_material), R.mipmap.pic_9);
        WorkFunctionBean workFunctionBean10 = new WorkFunctionBean(getResourcesString(R.string.material_fixed), R.mipmap.pic_10);
        WorkFunctionBean workFunctionBean11 = new WorkFunctionBean(getResourcesString(R.string.material_delivery), R.mipmap.pic_11);
        WorkFunctionBean workFunctionBean12 = new WorkFunctionBean(getResourcesString(R.string.material_receiving), R.mipmap.pic_12);
        //WorkFunctionBean workFunctionBean13 = new WorkFunctionBean(getResourcesString(R.string.receiving_confirmation), R.mipmap.pic_13);
        WorkFunctionBean workFunctionBean13 = new WorkFunctionBean(getResourcesString(R.string.feeding_operation), R.mipmap.pic_14);
        WorkFunctionBean workFunctionBean14 = new WorkFunctionBean(getResourcesString(R.string.new_transfer_list), R.mipmap.pic_15);
        WorkFunctionBean workFunctionBean15 = new WorkFunctionBean(getResourcesString(R.string.transfer_warehouse_delivery_goods), R.mipmap.pic_16);

        WorkFunctionBean workFunctionBean16 = new WorkFunctionBean(getResourcesString(R.string.transfer_warehouse_receive_goods), R.mipmap.pic_17);
        WorkFunctionBean workFunctionBean17 = new WorkFunctionBean(getResourcesString(R.string.transfer_warehouse_receive_goods_confirm), R.mipmap.pic_18);
        WorkFunctionBean workFunctionBean18 = new WorkFunctionBean(getResourcesString(R.string.inventory_query), R.mipmap.pic_19);
        WorkFunctionBean workFunctionBean19 = new WorkFunctionBean(getResourcesString(R.string.library_transfer), R.mipmap.pic_20);
        WorkFunctionBean workFunctionBean20 = new WorkFunctionBean(getResourcesString(R.string.attribute_transfer), R.mipmap.pic_21);
        WorkFunctionBean workFunctionBean21 = new WorkFunctionBean(getResourcesString(R.string.in_storage_consolidation), R.mipmap.pic_22);
        WorkFunctionBean workFunctionBean22= new WorkFunctionBean(getResourcesString(R.string.manager_check), R.mipmap.pic_23);
        //WorkFunctionBean workFunctionBean24 = new WorkFunctionBean(getResourcesString(R.string.vehicle_inspection), R.mipmap.pic_24);

        itemList.add(new BaseItemBean(workFunctionBean1));
        itemList.add(new BaseItemBean(workFunctionBean2));
        itemList.add(new BaseItemBean(workFunctionBean3));
        itemList.add(new BaseItemBean(workFunctionBean4));
        itemList.add(new BaseItemBean(workFunctionBean5));
        itemList.add(new BaseItemBean(workFunctionBean6));
        itemList.add(new BaseItemBean(workFunctionBean7));
        itemList.add(new BaseItemBean(workFunctionBean8));
        itemList.add(new BaseItemBean(workFunctionBean9));
        itemList.add(new BaseItemBean(workFunctionBean10));
        itemList.add(new BaseItemBean(workFunctionBean11));
        itemList.add(new BaseItemBean(workFunctionBean12));
        //itemList.add(new BaseItemBean(workFunctionBean13));
        itemList.add(new BaseItemBean(workFunctionBean13));
        itemList.add(new BaseItemBean(workFunctionBean14));
        itemList.add(new BaseItemBean(workFunctionBean15));
        itemList.add(new BaseItemBean(workFunctionBean16));
        itemList.add(new BaseItemBean(workFunctionBean17));
        itemList.add(new BaseItemBean(workFunctionBean18));
        itemList.add(new BaseItemBean(workFunctionBean19));
        itemList.add(new BaseItemBean(workFunctionBean20));
        itemList.add(new BaseItemBean(workFunctionBean21));
        itemList.add(new BaseItemBean(workFunctionBean22));
        //itemList.add(new BaseItemBean(workFunctionBean24));//【APP-车辆检查】功能作屏避处理，不显示该图标
    }

    private void initRecyclerView() {
        RecyclerViewUtil.initLinearLayoutGridLayout(mActivity, 4, mRecyclerView);
        mGridViewAdapter = CommonNormalAdapterUtil.initCommonNormalAdapter(R.layout.fragment_work_main_item, itemList, CommonNormalAdapter.FLAG_WORK_MAIN);
        mRecyclerView.setAdapter(mGridViewAdapter);
        mGridViewAdapter.setOnItemChildClickListener(new BaseQuickAdapter.OnItemChildClickListener() {
            @Override
            public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
                WorkFunctionBean workFunctionBean = (WorkFunctionBean) itemList.get(position).object;
                Bundle bundle = null;
                //跳转到对应的界面
                switch (position) {
                    case 0://入库定位
                        bundle = new Bundle();
                        bundle.putInt(Constants.FLAG_ACTIVITY_KEY, Constants.FLAG_ACTIVITY_IN_BOUND_LOCATION_UI);
                        bundle.putString("modleName", InAndOutBoundLocationModle.class.getName());
                        jumpActivity(getActivity(), SearchActivity.class, bundle);
//                        bundle = new Bundle();
//                        bundle.putInt(Constants.FLAG_ACTIVITY_KEY, Constants.FLAG_ACTIVITY_IN_BOUND_LOCATION_UI);
//                        jumpActivity(mActivity, InAndOutBoundLocationActivity.class, bundle);
                        break;
                    case 1://订单入库
                        bundle = new Bundle();
                        bundle.putInt(Constants.FLAG_ACTIVITY_KEY, Constants.FLAG_ACTIVITY_ORDER_IN_BOUND_UI);
                        bundle.putString("modleName", OrderInAndOutBoundModle.class.getName());
                        jumpActivity(getActivity(), SearchActivity.class, bundle);

//                        bundle = new Bundle();
//                        bundle.putInt(Constants.FLAG_ACTIVITY_KEY, Constants.FLAG_ACTIVITY_ORDER_IN_BOUND_UI);
//                        jumpActivity(mActivity, OrderInAndOutboundActivity.class, bundle);
                        break;
                    case 2://通知单入库
//                        bundle = new Bundle();
//                        bundle.putInt(Constants.FLAG_ACTIVITY_KEY, Constants.FLAG_ACTIVITY_NOTICE_LETTER_IN_BOUND_UI);
//                        jumpActivity(mActivity, NoticeLetterInAndOutBoundActivity.class, bundle);

                        bundle = new Bundle();
                        bundle.putInt(Constants.FLAG_ACTIVITY_KEY, Constants.FLAG_ACTIVITY_NOTICE_LETTER_IN_BOUND_UI);
                        bundle.putString("modleName", NoticeLetterInAndOutBoundModle.class.getName());
                        jumpActivity(getActivity(), SearchActivity.class, bundle);
                        break;
                    case 3://收货确认
//                        bundle = new Bundle();
//                        bundle.putInt(Constants.FLAG_ACTIVITY_KEY, Constants.FLAG_ACTIVITY_RECEIVING_GOODS_UI);
//                        jumpActivity(mActivity, ReceivingAndSendGoodsConfirmActivity.class, bundle);

                        bundle = new Bundle();
                        bundle.putInt(Constants.FLAG_ACTIVITY_KEY, Constants.FLAG_ACTIVITY_RECEIVING_GOODS_UI);
                        bundle.putString("modleName", ReceivingAndSendGoodsConfirmModle.class.getName());
                        jumpActivity(getActivity(), SearchActivity.class, bundle);
                        break;
                    case 4://出库定位
//                        bundle = new Bundle();
//                        bundle.putInt(Constants.FLAG_ACTIVITY_KEY, Constants.FLAG_ACTIVITY_OUT_BOUND_LOCATION_UI);
//                        jumpActivity(mActivity, InAndOutBoundLocationActivity.class, bundle);
                        bundle = new Bundle();
                        bundle.putInt(Constants.FLAG_ACTIVITY_KEY, Constants.FLAG_ACTIVITY_OUT_BOUND_LOCATION_UI);
                        bundle.putString("modleName", InAndOutBoundLocationModle.class.getName());
                        jumpActivity(getActivity(), SearchActivity.class, bundle);
                        break;
                    case 5://订单出库
//                        bundle = new Bundle();
//                        bundle.putInt(Constants.FLAG_ACTIVITY_KEY, Constants.FLAG_ACTIVITY_ORDER_OUT_BOUND_UI);
//                        jumpActivity(mActivity, OrderInAndOutboundActivity.class, bundle);
                        bundle = new Bundle();
                        bundle.putInt(Constants.FLAG_ACTIVITY_KEY, Constants.FLAG_ACTIVITY_ORDER_OUT_BOUND_UI);
                        bundle.putString("modleName", OrderInAndOutBoundModle.class.getName());
                        jumpActivity(getActivity(), SearchActivity.class, bundle);
                        break;
                    case 6://通知单出库
//                        bundle = new Bundle();
//                        bundle.putInt(Constants.FLAG_ACTIVITY_KEY, Constants.FLAG_ACTIVITY_NOTICE_LETTER_OUT_BOUND_UI);
//                        jumpActivity(mActivity, NoticeLetterInAndOutBoundActivity.class, bundle);

                        bundle = new Bundle();
                        bundle.putInt(Constants.FLAG_ACTIVITY_KEY, Constants.FLAG_ACTIVITY_NOTICE_LETTER_OUT_BOUND_UI);
                        bundle.putString("modleName", NoticeLetterInAndOutBoundModle.class.getName());
                        jumpActivity(getActivity(), SearchActivity.class, bundle);
                        break;
                    case 7://发货确认
//                        bundle = new Bundle();
//                        bundle.putInt(Constants.FLAG_ACTIVITY_KEY, Constants.FLAG_ACTIVITY_SEND_GOODS_UI);
//                        jumpActivity(mActivity, ReceivingAndSendGoodsConfirmActivity.class, bundle);

                        bundle = new Bundle();
                        bundle.putInt(Constants.FLAG_ACTIVITY_KEY, Constants.FLAG_ACTIVITY_SEND_GOODS_UI);
                        bundle.putString("modleName", ReceivingAndSendGoodsConfirmModle.class.getName());
                        jumpActivity(getActivity(), SearchActivity.class, bundle);
                        break;
                    case 8://创建领料单
                        Bundle bundle1 = new Bundle();
                        bundle1.putString("modleName", PickBillListModle.class.getName());
                        jumpActivity(getActivity(), SearchActivity.class, bundle1);
//                        TurnToActivity(CreateMaterialSheetActivity.class);
                        break;
                    case 9://领料定库
                        Bundle bundle2 = new Bundle();
                        bundle2.putString("modleName", PickBillSureWareHouseModle.class.getName());
                        jumpActivity(getActivity(), SearchActivity.class, bundle2);
                        break;
                    case 10://领料发货
                        Bundle bundle3 = new Bundle();
                        bundle3.putString("modleName", PickSendGoodsModle.class.getName());
                        jumpActivity(getActivity(), SearchActivity.class, bundle3);
                        break;
                    case 11://领料收货
                        Bundle bundle4 = new Bundle();
                        bundle4.putString("modleName", PickUpGoodsModle.class.getName());
                        jumpActivity(getActivity(), SearchActivity.class, bundle4);
                        break;
//                    case 12://领料收货确认
//                        Bundle bundle5 = new Bundle();
//                        bundle5.putString("modleName", PickCollectGoodSureModle.class.getName());
//                        jumpActivity(getActivity(), SearchActivity.class, bundle5);
//                        break;
                    case 12://投料作业
                        Bundle bundle6 = new Bundle();
                        bundle6.putString("modleName", FeedOperationOrderModle.class.getName());
                        jumpActivity(getActivity(), SearchActivity.class, bundle6);
                        break;
                    case 13://新建移库单
                        jumpActivity(getActivity(), CreateMoveWareHouseSheetActivity.class);
                        break;
                    case 14://移库发货
                        Bundle bundle7 = new Bundle();
                        bundle7.putString("modleName", MoveHouseGoodsModle.class.getName());
                        jumpActivity(getActivity(), SearchActivity.class, bundle7);
                        break;
                    case 15://移库收货
                        Bundle bundle8 = new Bundle();
                        bundle8.putString("modleName", TakeDeliveryModel.class.getName());
                        jumpActivity(getActivity(), SearchActivity.class, bundle8);
//                        startActivity(new Intent(mActivity, TakeDeliveryActivity.class));
                        break;
                    case 16://移库收货确认
                        Bundle bundle9 = new Bundle();
                        bundle9.putString("modleName", ChangeAndGetGoodsModle.class.getName());
                        jumpActivity(getActivity(), SearchActivity.class, bundle9);
//                        startActivity(new Intent(mActivity, ChangeAndGetGoodsNotifyListActivity.class));
                        break;
                    case 17://库存查询
//                        startActivity(new Intent(mActivity, ScanActivity.class));
                        startActivity(new Intent(mActivity, RepertorySearchActivity.class));
                        break;
                    case 18://库位转移
                        startActivity(new Intent(mActivity, RepertoryChangeActivity.class));
                        break;
                    case 19://属性转移
                        startActivity(new Intent(mActivity, AttributeChangeActivity.class));
                        break;
                    case 20://在库整理
                        startActivity(new Intent(mActivity, ReorganizeActivity.class));
                        break;
                    case 21://盘点管理
                        startActivity(new Intent(mActivity, CheckManagerActivity.class));
                        break;
//                    case 22://车辆检查
//                        startActivity(new Intent(mActivity, CheckCartActivity.class));
//                        break;
                }
            }
        });
    }

    private String getResourcesString(int resourcesId) {
        String mResourcesStr = mActivity.getResources().getString(resourcesId);
        return mResourcesStr;
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.fragment_work_main_scanImageView:
                Utils.startScanActivity(mActivity);
        }
    }

    public void TurnToActivity(Class<?> cls) {
        Intent mIntent = new Intent(mActivity, cls);
        startActivity(mIntent);
    }

}
